package pers.cnzdy.tutorial.Chapter5_UI.Section8_Fragment;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

import pers.cnzdy.tutorial.Chapter5_UI.Section7_ListView.KnowledgePoints;
import pers.cnzdy.tutorial.R;


public class KPointsAdapter extends ArrayAdapter<KnowledgePoints.KnowledgePoint> {
    int resourceId;

    public KPointsAdapter (Context context, int textViewResourceId,
                           List<KnowledgePoints.KnowledgePoint> objects) {
        super(context, textViewResourceId, objects);
        resourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        KnowledgePoints.KnowledgePoint kpoint = getItem(position);
        View view;
        if (convertView == null) {
            view = LayoutInflater.from(getContext()).inflate(resourceId, null);
        } else {
            view = convertView;
        }
        TextView newsTitleText = view.findViewById(R.id.kpoint_caption);
        newsTitleText.setText(kpoint.getCaption());
        return view;
    }
}